package edu.utd.text.game.controller.commands;

import edu.utd.text.game.controller.Controller;
import edu.utd.text.game.domain.exceptions.GameObjectNotFoundException;
import edu.utd.text.game.domain.item.GameItem;
import edu.utd.text.game.domain.player.Player;

public class DropItemCommand implements GameCommand {
	private String itemToDrop;
	
	public DropItemCommand(String itemToDrop) {
		this.itemToDrop = itemToDrop;
	}
	
	public String getItemToDrop() { 
		return itemToDrop; 
	}
	
	public void setItemToDrop(String itemToDrop) { 
		this.itemToDrop = itemToDrop; 
	}
	
	
	
	public String execute() {
	
		Controller controller = Controller.INSTANCE;
		Player player = controller.getPlayer();
	
		if (player.hasItem(itemToDrop)) {
			try {
				GameItem theItem = player.getItemFromInventory(itemToDrop);
			
				if (player.dropItemInRoom(theItem)) {	
					return "Dropped " + theItem.getName();
				}
				else {
					return "Cannot drop that here.";
				}
			} catch (GameObjectNotFoundException gonfx) {
				; // fall thru to the return
			}
		}
		return "You are not carrying one of those!";
	}
}
